package tree;

import java.util.ArrayList;
import java.util.List;

public class TreeObject<T, E> {
	private TreeNode<T, E> node;
	private List<TreeObject<T, E>> childList = new ArrayList<TreeObject<T, E>>();

	private TreeObject(TreeNode<T, E> node) {
		this.node = node;
	}

	public TreeObject(HashTree<T, E> tree) {
		initTreeNode(this, tree.getChildNodes(tree.getRootId()), tree);
	}

	public TreeObject(HashTree<T, E> tree, T rootId) {
		initTreeNode(this, tree.getChildNodes(rootId), tree);
	}

	private void initTreeNode(TreeObject<T, E> treeObj, List<TreeNode<T, E>> list, HashTree<T, E> tree) {
		for (TreeNode<T, E> node : list) {
			TreeObject<T, E> obj = new TreeObject<T, E>(node);
			treeObj.childList.add(obj);
			initTreeNode(obj, tree.getChildNodes(node.getId()), tree);
		}
	}

	public TreeNode<T, E> getNode() {
		return node;
	}

	public void setNode(TreeNode<T, E> node) {
		this.node = node;
	}

	public List<TreeObject<T, E>> getChildList() {
		return childList;
	}

	public void setChildList(List<TreeObject<T, E>> childList) {
		this.childList = childList;
	}
}
